<?php
class Zend_Controller_Action_Helper_ParsePageTree extends Zend_Controller_Action_Helper_Abstract
{
	private $level;
	private $parsedPages;

	public function __construct()
	{
		$this->parsedPages = array();
	}

	public function direct($pages, $level = 0)
	{
		foreach($pages as $id => $page) {
			$pageName = '';
			if(array_key_exists('name', $page)) {
				if(is_array($page['name'])) {
					foreach($page['name'] as $pageL10N) {
						if(empty($pageName)) {
							$pageName .= $pageL10N;
						} else {
							$pageName .= " ({$pageL10N})";
						}
					}
				}
			}

			$this->parsedPages[$id] = str_repeat('—', $level) . ' ' . $pageName;

			if(array_key_exists('children', $page)) {
				$this->direct($page['children'], $level + 1);
			}
		}

		return $this->parsedPages;
	}
}